
package com.scs.application.modules.doc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.service.BaseServiceImpl;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.doc.entity.FileUpload;
import com.scs.application.modules.doc.mapper.FileUploadMapper;
import com.scs.application.modules.doc.request.FileUploadQueryRequest;
import com.scs.application.modules.doc.service.FileUploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* 上传记录 service 实现
*/
@Slf4j
@Service
public class FileUploadServiceImpl extends BaseServiceImpl<FileUploadMapper, FileUpload> implements FileUploadService {

    @Override
    public List<FileUpload> list(FileUploadQueryRequest request) {
        List<FileUpload> list = this.list(Wrappers.<FileUpload>query()
                .eq(request.getFileId() != null, "file_id", request.getFileId())
                .eq(StringUtils.isNotBlank(request.getBizType()), "biz_type", request.getBizType())
                .eq(StringUtils.isNotBlank(request.getBizKey()), "biz_key", request.getBizKey())
            .orderByDesc("gmt_modified")
        );
        return list;
    }

    @Override
    public IPage<FileUpload> page(FileUploadQueryRequest request) {
        IPage page = this.page(request.getPage(), Wrappers.<FileUpload>query()
                .eq(request.getFileId() != null, "file_id", request.getFileId())
                .eq(StringUtils.isNotBlank(request.getBizType()), "biz_type", request.getBizType())
                .eq(StringUtils.isNotBlank(request.getBizKey()), "biz_key", request.getBizKey())
            .orderByDesc("gmt_modified")
        );
        return page;
    }
}
